<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>系统公告</title>
	<link type="text/css" rel="stylesheet" href="../<s:property value="#session.themeStyle.mainCss" default="Skin/PM/LightBlue/main.css"/>" />
</head>
<body>
	<div class="navBar">
		当前位置：个人信息&gt;&gt;公告信息
	</div>
	<s:form theme="simple">
	<fieldset class="query">
		<legend class="title">查询条件</legend>
		<ul style="margin-top: 0px;margin-left: 0px;">
			<li class="titles">
				标 题：
			</li>
			<li class="inputs">
				<input class="inputText" name="title" id="title" type="text" value="${title}" maxlength="50" style="color: #5F9EA0;font-style: italic; " onblur="changeBegin(this.id,'请输入查询内容')" onfocus="changeEnd(this.id,'请输入查询内容')"  />
			</li>
			<li class="titles">
				开始时间：
			</li>
			<li class="inputs">
				<input class="Wdate" name="startTime" id="startTime" type="text" value="${startTime}" onfocus="WdatePicker()" style="color: #5F9EA0;font-style: italic; " onClick="WdatePicker()" onfocus="changeEnd(this.id,'请选择日期')"  />
			</li>
			<li class="titles">
				结束时间：
			</li>
			<li class="inputs">
				<input class="Wdate" name="endTime" id="endTime" type="text" value="${endTime }" onfocus="WdatePicker()" style="color: #5F9EA0;font-style: italic; " onClick="WdatePicker()" onfocus="changeEnd(this.id,'请选择日期')"  />
			</li>
			<li style="float: left; margin-left: 20px; margin-top: 0px;">
				<a class="but28" onclick="getData()" style="text-decoration: none;">查询</a>
			</li>
		</ul>
	</fieldset>
	<div class="tabBlock" style="margin-top: 0px;">
		<div class="dataGrid">
			<table id="divTable" style="table-layout: fixed;">
				<tr>
					<th style="width: 20%;">
						标题
					</th>
					<th style="width: 25%;">
						内容
					</th>
					<th style="width: 10%;">
						创建者
					</th>
					<th style="width: 15%;">
						创建时间
					</th>
					<th>
						操作
					</th>
				</tr>
				<s:iterator value="result.resultlist" status="st" var="cus">
					<tr class="trStyle">
						<td>
							<s:if test="%{null!=#cus.title&&#cus.title.length()>20}">
		          				<s:property value="#cus.title.substring(0,20)+'...'" />
				   			 </s:if>
				   			 <s:else>
			            		<s:property value="#cus.title" />
				   			 </s:else>
							
							&nbsp;
						</td>
						<td style="white-space: nowrap; overflow: hidden;text-align: left;">
							<s:property value="#cus.content" />
							&nbsp;
						</td>
						<td>
							<s:property value="#cus.creater" />
							&nbsp;
						</td>
						<td>
							<s:date name="#cus.messPublishDate" format="yyyy-MM-dd HH:mm:ss" />
							&nbsp;
						</td>
						<td>
							<a onclick="detail(<s:property value="#cus.pkId" />)" target="mainFrame" style="color: #E9621E; cursor: pointer;">详情</a>&nbsp;
							<a onclick="edit(<s:property value="#cus.pkId" />)" target="mainFrame" style="color: #E9621E; cursor: pointer;">编辑</a>&nbsp;
							<a onclick="del(<s:property value="#cus.pkId" />)" target="mainFrame" style="color: #E9621E; cursor: pointer;">删除</a>&nbsp;
						</td>
					</tr>
				</s:iterator>
				<tr class="trBotton">
					<td colspan="5">
						<s:if test="count > 10">
						页数：<s:property value="page" />/<s:property value="allPages" /> ｜
						总数：<s:property value="count" /> ｜ 当前页：
						<select id="selectNowpage" style="width: 40px" name="page" onChange="changePageNum(this)">
								<s:bean name="org.apache.struts2.util.Counter" id="counter">
									<s:param name="first" value="1" />
									<s:param name="last" value="allPages" />
									<s:iterator>
										<option value="<s:property/>" ${page==i?"selected" : ""}>
											<s:property />
										</option>
									</s:iterator>
								</s:bean>
							</select>
						｜ 每页数：
						<select id="selectMaxPage" style="width: 50px" name="rowsPage" onChange="modPageSize(this)">
								<option value="10">
									10
								</option>
								<option value="20">
									20
								</option>
								<option value="50">
									50
								</option>
								<option value="100">
									100
								</option>
							</select>
							<s:if test="page > 1">
								<a href="javascript:upDown(1)">&lt;&lt;</a>
								<a href="javascript:upDown(${page - 1})">上页</a>
							</s:if>
							<s:if test="page < allPages">
								<a href="javascript:upDown(${page+1})">下页</a>
								<a href="javascript:upDown(${allPages})">&gt;&gt;</a>
							</s:if>
						</s:if>
					</td>
				</tr>
			</table>
		</div>
		<div style="width: 100%;text-align: center;">
			<a class="but39" onclick="createMessage()" style="text-decoration: none;">新建</a>
		</div>
	</div>
	<input type="hidden" id="rowsPage" value='<s:property value="rowsPage"/>' />
	<input type="hidden" id="page" value='<s:property value="page"/>' />
	</s:form>
	<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/store.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#selectMaxPage").val($("#rowsPage").val());
			$("#selectNowpage").val($("#page").val());
			if($("#title").val()==""){
				$("#title").val("请输入查询内容");
			}
			if($("#startTime").val()==""){
				$("#startTime").val("请选择日期");
			}
			if($("#endTime").val()==""){
				$("#endTime").val("请选择日期");
			}
			var height = window.parent.document.getElementById("mainFrame").height-$("#tableTop").height()-58;
		});
		/* 改变每页显示条数时，需要自动跳转到第一页 */
		function modPageSize(obj) {
			var size = $(obj).val();
			$("#rowsPage").val(size);
			getData();
		}
		
		/* 翻页时同时修改select控件页面数 */
		function upDown(n) {
			$("#page").val(n);
			getData();
		}
		function changePageNum(obj) {
			var page = $(obj).val();
			$("#page").val(page);
			getData();
		}
	
		function getData(){
			var page = $.trim($("#page").val());
			var rowsPage = $.trim($("#rowsPage").val());
			var title = $("#title").val();
			var startTime = $("#startTime").val();
			var endTime = $("#endTime").val();
		    var str = $("#startTime").val().replace(/\-/g, "\/");
			var str1 = $("#endTime").val().replace(/\-/g, "\/");
			if(str>str1){
			    alert("结束时间不能小于开始时间");
			    $("#startTime").val("请选择日期");
			    $("#endTime").val("请选择日期");
			    return;
			}
			var url = $("form")[0].action;
	   		var from = createFrom(url);
	   		if (startTime=="请选择日期"){
				startTime=""
			}
			if (endTime=="请选择日期"){
				endTime=""
			}
			if (title=="请输入查询内容"){
				title=""
			}
	   		if(page!=""){
				loadFrom("page",page,from);	
			}
			if(rowsPage!=""){
				loadFrom("rowsPage",rowsPage,from);	
			}
	   		if(title!=""){
	   			loadFrom("title",title,from);
			}
	   		if(startTime!=""){
	   			loadFrom("startTime",startTime,from);
			}
	   		if(endTime!=""){
				loadFrom("endTime",endTime,from)
			}
	   		from.submit();
		
		}
		
		function del(id){
			if(confirm("真的要删除该公告信息吗？")){
				var url = "sysMessage-del.action";
				$.ajax({
					url: url,
					data: {mid: id},
					dataType: "json",
					success: function(result){
						if(result.success){
							alert("公告信息已经删除！");
							location.reload();
						}else{
							alert("公告信息删除时发生错："+result.errorMessage);
						}
					}
				});
			}
		}
		
		function edit(mId){
				window.location.href = "sysMessage-edit.action?mid="+mId;
		}
	
		function detail(mId){
				window.location.href = "sysMessage-view.action?mid="+mId;
		}
		
		function createMessage(){
				window.location.href = "sysMessage-add.action";
		}
		
		function changeBegin(cs_id,value){ 
			var str_text = document.getElementById(cs_id);
				if (str_text.value==""){
					str_text.value=value;
				}
		}
		function changeEnd(cs_id,value){ 
			var str_text = document.getElementById(cs_id);
				if (str_text.value==value){
					str_text.value="";
				}
		}
	
	</script>
</body>
</html>